<template>
  <view class="demo-container">
    <!-- 基础用法 -->
    <view class="demo-block">
      <view class="demo-block__title">基础用法</view>
      <view class="demo-block__content">
        <fu-button type="primary" @click="show1 = true">单列选择</fu-button>
        <fu-picker
          v-model:show="show1"
          title="选择城市"
          :columns="columns1"
          :value="value1"
          @confirm="onConfirm1"
          @cancel="onCancel"
          @change="onChange1"
        />
      </view>
    </view>
    
    <!-- 多列选择 -->
    <view class="demo-block">
      <view class="demo-block__title">多列选择</view>
      <view class="demo-block__content">
        <fu-button type="primary" @click="show2 = true">多列选择</fu-button>
        <fu-picker
          v-model:show="show2"
          title="选择时间"
          :columns="columns2"
          :value="value2"
          @confirm="onConfirm2"
          @cancel="onCancel"
          @change="onChange2"
        />
      </view>
    </view>
    
    <!-- 对象数组 -->
    <view class="demo-block">
      <view class="demo-block__title">对象数组</view>
      <view class="demo-block__content">
        <fu-button type="primary" @click="show3 = true">对象数组</fu-button>
        <fu-picker
          v-model:show="show3"
          title="选择地区"
          :columns="columns3"
          :value="value3"
          value-key="name"
          @confirm="onConfirm3"
          @cancel="onCancel"
          @change="onChange3"
        />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      show1: false,
      show2: false,
      show3: false,
      
      // 单列数据
      columns1: ['北京', '上海', '广州', '深圳', '杭州', '南京', '武汉', '成都'],
      value1: [0],
      
      // 多列数据
      columns2: [
        ['上午', '下午'],
        ['00', '15', '30', '45'],
      ],
      value2: [0, 0],
      
      // 对象数组
      columns3: [
        [
          { id: 1, name: '广东省' },
          { id: 2, name: '浙江省' }
        ],
        [
          { id: 11, name: '广州市' },
          { id: 12, name: '深圳市' }
        ]
      ],
      value3: [0, 0]
    }
  },
  methods: {
    // 单列选择
    onConfirm1(value) {
      uni.showToast({
        title: `选择了：${this.columns1[value[0]]}`,
        icon: 'none'
      })
    },
    onChange1(value) {
      this.value1 = value
    },
    
    // 多列选择
    onConfirm2(value) {
      const time = `${this.columns2[0][value[0]]} ${this.columns2[1][value[1]]}`
      uni.showToast({
        title: `选择了：${time}`,
        icon: 'none'
      })
    },
    onChange2(value) {
      this.value2 = value
    },
    
    // 对象数组
    onConfirm3(value) {
      const province = this.columns3[0][value[0]].name
      const city = this.columns3[1][value[1]].name
      uni.showToast({
        title: `选择了：${province} ${city}`,
        icon: 'none'
      })
    },
    onChange3(value) {
      this.value3 = value
    },
    
    // 取消选择
    onCancel() {
      uni.showToast({
        title: '取消选择',
        icon: 'none'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.demo-container {
  padding: 20rpx;
}

.demo-block {
  margin-bottom: 30rpx;
  
  &__title {
    margin-bottom: 20rpx;
    font-size: var(--fu-font-size-lg);
    color: var(--fu-text-color);
  }
  
  &__content {
    background-color: #fff;
    padding: 30rpx;
    border-radius: var(--fu-radius-base);
  }
}
</style> 